package cn.kpi.service.teamassement.Impl;

import cn.kpi.dao.teamassessment.BUKPIDao;
import cn.kpi.entity.teamassessment.BUKPItemEntity;
import cn.kpi.service.teamassement.IBUKPIService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.util.List;
import java.util.Map;

/**
 * 队伍考核打分
 *
 * @author lex
 * @create 2018-06-20-11:22
 */
@Controller
public class BUKPIServiceImpl implements IBUKPIService {


    @Autowired
    private BUKPIDao bukpiDao;


    @Override
    public List<Map> GetBUKPIMapByTempIdAndColumns(Long tempid, String columns) throws Exception {
        try {
            return bukpiDao.GetBUKPIMapByTempIdAndColumns(tempid, columns);
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    @Override
    public List<Map> GetBUKPIMapByTempId(String itemids,int divisor) throws Exception {
        try {
            return bukpiDao.GetBUKPIMapByTempId(itemids,divisor);
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    @Override
    public int InsertBUKPItemBatch(Long templateid, List<BUKPItemEntity> list) throws Exception {
        try {
            int result = bukpiDao.DeleteBUKPItem(templateid);
            result += bukpiDao.InsertBUKPItemBatch(list);
            return result;
        } catch (Exception ex) {
            ex.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();//回滚事物
            return -1;
        }
    }
}
